package com.duofan.gmall.order.controller;

import com.alibaba.fastjson.JSON;
import com.duofan.gmall.order.entity.OrderEntity;
import com.duofan.gmall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@Slf4j
@RestController
public class RabbitController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg/{num}")
    public String sendMsg(@PathVariable Long num) {
        for (long i = 0; i < num; i++) {
            OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
            entity.setId(i);
            entity.setCreateTime(new Date());
            rabbitTemplate.convertAndSend("hello-java-exchange", "hello-java", entity,
                    new CorrelationData(UUID.randomUUID().toString()));
        }
/*
        for (long i = 0; i < num; i++) {
            OrderEntity entity = new OrderEntity();
            entity.setId(i);
            entity.setCreateTime(new Date());
            rabbitTemplate.convertAndSend("hello-java-exchange", "hello-java", entity,
                    new CorrelationData(UUID.randomUUID().toString()));
        }*/
        return "ok";
    }
}
